---
title: BM25 Scoring
---

## Overview

BM25 scores measure how relevant a score is for a given query. Higher scores indicate higher relevance.

## Basic Usage

Call `paradedb.rank_bm25` in a SELECT statement, passing in the `key_field` column.

If you are using two calls to `search` in the same transaction, you must pass a string `alias` argument to `search` and `rank_bm25` to identify which set of bm25 scores to use.

```sql
SELECT *, paradedb.rank_bm25(<key_field>) FROM <index_name>.search('<query>');
```

<Accordion title="Example Usage">

```sql
SELECT *, paradedb.rank_bm25(id)
FROM search_idx.search(
	query => paradedb.boolean(
		should => ARRAY[
			paradedb.fuzzy_term(field => 'description', value => 'keyboard'),
			paradedb.fuzzy_term(field => 'category', value => 'electronics')
		]
	)
);

-- Multiple calls to search, alias is required.
SELECT id, paradedb.rank_bm25(id)
FROM search_idx.search('description:shoes')
UNION
SELECT id, paradedb.rank_bm25(id, alias => 'speaker')
FROM search_idx.search('description:speaker', alias => 'speaker')
ORDER BY id;
```

</Accordion>

<ParamField body="key_field" required>
  The column that represents the `key_field` of the index.
</ParamField>
<ParamField body="alias">
  A string identifier passed both to `search` and `rank_bm25`. This is required
  only if you're using two `search` calls in one transaction, as `rank_bm25`
  cannot otherwise know which set of scores to use.
</ParamField>
